var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var UserSchema = new Schema({
    userid: {
        type: String,
        trim: true
    },//
    password: {
        type: String
    },
    username: {
        type: String,
        trim: true
    },
    classid: {
        type: String,
        default: '',
        trim: true//去掉首尾空格
    },
    mobile: {
        type: String,
        default: '',
        trim: true
    },
    mail: {
        type: String,
        default: '',
        trim: true
    },
    roomnumber: {
        type: String,
        default: '',
        trim: true
    },
    department: {
        type: Number,
        required: "部门不能为空"
    },
    position: {
        type: Number,
        required: '职位不能为空'
    },
    note: {
        type: String,
        default: '',
        trim: true
    },
    date: {
        type: Date,
        default: Date.now
    },
    birthday: {
        type: String,
        default: '',
        trim: true
    },
    userno: {
        type: String,
        required: "学号不能为空",
        trim: true
    },
    validated: {
        type: Boolean,
        default: false
    },
    gender: {
        type: Number,
        default: 0
    },
    dep: {
        type: String
    },
    usericon: {
        type: String,
        default: 'default_boy.png'
    },
    thumbArticles: [Schema.Types.ObjectId],
    loveArticles: [Schema.Types.ObjectId],
    /**
     * commentsBy: [{
     *  如果已登录
     *  uid: ObjectId,
     *  username: String,
     *  usericon: String,
     *  userdep: String,
     *  date: Date,
     *  content: String
     * },
     * {
     *  如果未登录
     *  name: String,
     *  email: String,
     *  ip: String,
     *  content: String
     * }
     * ...
     * ]
     */
    commentsBy: [Schema.Types.Mixed],
    articleNum: {
        type: Number,
        default: 0
    },
    thumbedNum: {
        type: Number,
        default: 0
    },
    visitedNum: {
        type: Number,
        default: 0
    },
    commentedNum: {
        type: Number,
        default: 0
    },
    avatar: {
        type: Number,
        default: 1
    }
});

mongoose.model('User', UserSchema);

console.log('模型已经建立...');
